//
//  FKCommodityComment.m
//  HappyTest
//
//  Created by Macbook Pro on 2019/2/16.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKCommodityComment.h"

@implementation FKCommodityComment

- (void)mj_keyValuesDidFinishConvertingToObject
{
    _addTime = [_add_time fk_timeWithFormat:@"yyyy-MM-dd"];
    
    if (_content.length == 0) {
        _content = @"此用户没有填写评价。";
    }
    
    NSMutableArray *array = [NSMutableArray array];
    NSInteger columns = _img.count % 4 == 0 ? 2 : 3;
    CGFloat imgWH = fk_adjustW(112);
    CGFloat imgMargin = fk_adjustW(6);
    CGFloat imgContainerH = 0;
    for (NSInteger index = 0; index < _img.count; index++) {
        NSInteger row = index / columns;
        NSInteger column = index % columns;
        CGFloat imageX = 15 + column * (imgWH + imgMargin);
        CGFloat imageY = row * (imgWH + imgMargin);
        CGRect imageF = CGRectMake(imageX, imageY, imgWH, imgWH);
        [array addObject:@(imageF)];
        if (index == _img.count - 1) {
            imgContainerH = CGRectGetMaxY(imageF);
        }
    }
    _imgFrames = array;
    
    CGFloat avatarH = fk_adjustW(30);
    CGFloat contentToAvatarMargin = fk_adjustW(40);
    CGFloat contentH = [_content boundingRectWithSize:CGSizeMake(fkScreenW - 30, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : fk_adjustFont(14)} context:nil].size.height;
    if (imgContainerH == 0) {
        _cellH = 14 + avatarH + contentToAvatarMargin + contentH + 15;
    } else {
        _cellH = 14 + avatarH + contentToAvatarMargin + contentH + 14 + imgContainerH + 15;
    }
}

@end
